package cc.orange.adapter;

import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import cc.orange.entity.FriendItemInfo;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cc.orange.R;

public class ChatFriendItemAdapter extends BaseQuickAdapter<FriendItemInfo.DataDTO.SocWomenDTO, BaseViewHolder> {

    private List<FriendItemInfo.DataDTO.SocWomenDTO> data;

    private OnFollowClick onFollowClick;

    /**
     *  1: 聊友页面
     *  2: 已关注
     *  3: 关注
     */
    private int type = -1;

    public ChatFriendItemAdapter( @Nullable List<FriendItemInfo.DataDTO.SocWomenDTO> data, int type) {
        super(R.layout.item_chat_friend, data);
        this.data = data;
        this.type = type;
    }

    public void setOnFollowClick(OnFollowClick onFollowClick) {
        this.onFollowClick = onFollowClick;
    }

    public void updateData(List<FriendItemInfo.DataDTO.SocWomenDTO> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FriendItemInfo.DataDTO.SocWomenDTO item) {
        TextView tvFollow, tvUserName, tvAge, tvPosition, tvContent;
        ImageView civHead;
        LinearLayout llPosition;
        tvFollow = helper.getView(R.id.tv_follow);
        tvAge = helper.getView(R.id.tv_age);
        tvUserName = helper.getView(R.id.tv_username);
        tvPosition = helper.getView(R.id.tv_position);
        tvContent = helper.getView(R.id.textView);
        civHead = helper.getView(R.id.civ_head);
        llPosition = helper.getView(R.id.ll_position);
        switch (type) {
            case 1:
                tvFollow.setText("私聊");
                break;
            case 2:
                tvFollow.setText("已关注");
                tvFollow.setTextColor(Color.parseColor("#aaaaaa"));
                tvFollow.setBackgroundResource(R.drawable.bg_chat_unfollow);
                break;
            case 3:
                tvFollow.setTextColor(Color.parseColor("#FF61A0"));
                tvFollow.setBackgroundResource(R.drawable.bg_chat_follow);
                tvFollow.setText("关注");
                break;
        }
        tvFollow.setOnClickListener(view1 -> {
            Log.e("click", "点击了关注" );
            if (onFollowClick != null) {
                onFollowClick.onFollowClick(helper.getAdapterPosition(), tvFollow);
            }
        });
        tvContent.setText(""+item.getIntroduce());
        tvAge.setText(item.getAge()+ "");
        tvPosition.setVisibility(View.GONE);
        tvUserName.setText(item.getName());
        String socialPurpose = item.getSocialPurpose();
//        if (socialPurpose != null) {
//            llPosition.setVisibility(View.VISIBLE);
//            tvContent.setText(socialPurpose);
//        } else {
//            llPosition.setVisibility(View.GONE);
//        }
        Glide.with(civHead.getContext()).load(item.getHeadPhoto()).into(civHead);
    }

    public interface OnFollowClick {
        void onFollowClick(int pos, View view);
    }
}
